// {+}

package mb.view;

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.net.URL;

public class AppAbout extends JDialog implements ActionListener {

  private static final String IMAGE_PATH = "images/aboutMagic.gif";

  private String empty = "";
  private String product = " Magic Boxes";
  private String version = " Java";
  private String date = " 1997 - 2007";
  private String author = " Dzenan Ridjanovic";

  private JPanel northPanel = new JPanel();
  private JPanel southPanel = new JPanel();
  private JPanel centerPanel = new JPanel();
  private JPanel westPanel = new JPanel();
  private JPanel eastPanel = new JPanel();

  private JPanel imagePanel = new JPanel();
  private JPanel textPanel = new JPanel();

  private ImageIcon imageIcon = this.getImageIcon(IMAGE_PATH);

  private JLabel label0 = new JLabel();
  private JLabel label1 = new JLabel();
  private JLabel label2 = new JLabel();
  private JLabel label3 = new JLabel();
  private JLabel label4 = new JLabel();
  private JLabel imageLabel = new JLabel(imageIcon);

  private JButton button = new JButton("OK");

  private BorderLayout borderLayout1 = new BorderLayout();
  private BorderLayout borderLayout2 = new BorderLayout();
  private GridLayout gridLayout = new GridLayout();
  private FlowLayout flowLayout = new FlowLayout();

  public AppAbout(AppFrame parent) {
    super(parent); // different from the default constructor
    try {
      this.init();
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
    this.pack();
  }

  private void init() throws Exception {
    this.setTitle("About...");
    this.setResizable(false);

    Container cp = this.getContentPane();
    cp.setLayout(borderLayout1);
    cp.add(northPanel, BorderLayout.NORTH);
    cp.add(southPanel, BorderLayout.SOUTH);
    cp.add(centerPanel, BorderLayout.CENTER);
    cp.add(westPanel, BorderLayout.WEST);
    cp.add(eastPanel, BorderLayout.EAST);

    centerPanel.setLayout(borderLayout2);
    centerPanel.add(imagePanel, BorderLayout.NORTH);
    centerPanel.add(textPanel, BorderLayout.SOUTH);

    imagePanel.setBackground(Color.ORANGE);
    imagePanel.add(imageLabel);

    textPanel.setLayout(gridLayout);
    textPanel.setBackground(Color.ORANGE);
    gridLayout.setRows(5);
    gridLayout.setColumns(1);
    label0.setText(empty);
    label1.setText(product);
    label2.setText(version);
    label3.setText(date);
    label4.setText(author);
    textPanel.add(label0);
    textPanel.add(label1);
    textPanel.add(label2);
    textPanel.add(label3);
    textPanel.add(label4);

    southPanel.setLayout(flowLayout);
    southPanel.add(button);
    button.addActionListener(this);
  }

  private ImageIcon getImageIcon(String anImage) {
    URL url = null;
    ImageIcon imageIcon = null;
    try {
      url = this.getClass().getResource(anImage);
      imageIcon = new ImageIcon(url);
    }
    catch (Exception e) {
      System.out.println(e.getMessage() + " // no URL");
    }
    return imageIcon;
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button) {
    this.setVisible(false);
    this.dispose();
    }
  }

}


